package com.feiyu.admin.service.impl;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feiyu.common.utils.PageUtils;
import com.feiyu.common.utils.Query;

import com.feiyu.admin.dao.CheckShopDao;
import com.feiyu.admin.entity.CheckShopEntity;
import com.feiyu.admin.service.CheckShopService;


@Service("checkShopService")
public class CheckShopServiceImpl extends ServiceImpl<CheckShopDao, CheckShopEntity> implements CheckShopService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<CheckShopEntity> wrapper = new QueryWrapper<>();
        if (params.get("checkState") != "" && params.get("shopType") == "" && params.get("fuzzyKey") == "") {
            wrapper.eq("check_state", params.get("checkState"));
        } else if (params.get("checkState") == "" && params.get("shopType") != "" && params.get("fuzzyKey") == "") {
            wrapper.eq("shop_type", params.get("shopType"));
        } else if (params.get("checkState") == "" && params.get("shopType") == "" && params.get("fuzzyKey") != "") {
            wrapper.like("shop_name", params.get("fuzzyKey"));
        } else if (params.get("checkState") != "" && params.get("shopType") != "" && params.get("fuzzyKey") == "") {
            wrapper.eq("check_state", params.get("checkState"))
                    .eq("shop_type", params.get("shopType"));
        } else if (params.get("checkState") != "" && params.get("shopType") == "" && params.get("fuzzyKey") != "") {
            wrapper.eq("check_state", params.get("checkState"))
                    .like("shop_name", params.get("fuzzyKey"));
        } else if (params.get("checkState") == "" && params.get("shopType") != "" && params.get("fuzzyKey") != "") {
            wrapper.eq("shop_type", params.get("shopType"))
                    .like("shop_name", params.get("fuzzyKey"));
        } else if(params.get("checkState") != "" && params.get("shopType") != "" && params.get("fuzzyKey") != ""){
            wrapper.eq("check_state", params.get("checkState"))
                    .eq("shop_type", params.get("shopType"))
                    .like("shop_name", params.get("fuzzyKey"));
        }
        IPage<CheckShopEntity> page = this.page(
                new Query<CheckShopEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}